/***************************************************************************
 *   Copyright (C) 2008 by Rysiek Król,,,   *
 *   rysiek@Babylon2   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "property.h"

#include <QSettings>

/**
* Konstruktor klasy
*/
Property::Property()
{
        this->readProperty();
}

/**
* Destruktor Klasy
*/
Property::~Property()
{
}

/**
* Zapisywanie Ustawień na dysku
*/
void Property::saveProperty()
{
        QSettings settings ( "AliceViewer", "AliceViewer" );
        settings.setValue ( "PictureDirectory",  this->pictureDir.absolutePath() );
        settings.setValue ( "ShowPictureScalled", this->showScalledPictures );
        settings.setValue( "WindowPosition", this->windowPosition);
        settings.setValue( "WindowSize", this->windowSize);
        settings.setValue( "IconSortingMethod", this->sortMethod);
}

/**
* Wczytywanie ustawień z dysku
*/
void Property::readProperty()
{
        QSettings settings ( "AliceViewer", "AliceViewer" );
        this->pictureDir = QDir(settings.value ( "PictureDirectory",QDir().absolutePath() ).value<QString>());
        this->showScalledPictures = settings.value ( "ShowPictureScalled", true ).toBool();
        this->windowPosition = settings.value("WindowPosition", QPoint(100, 100)).toPoint();
        this->windowSize = settings.value("WindowSize", QSize(1000, 800)).toSize();
        this->sortMethod = (Property::SortMethod) settings.value( "IconSortingMethod", Property::ByCommentDate).value<int>();
}



/**
* Zwraca parametr showScalledPictures odpowiedzialny za skalowanie obrazów.
*/
bool Property::getShowScalledPictures() const
{
        return showScalledPictures;
}

/**
* Ustawia parametr showScalledPictures]
* @param bool - jeśli jest ustawiony na true obrazy mniejsze od wielkości ekranu są skalowane, jeśli jest ustawiony na false, sa pokazywane w orginalnej rozdzielczosci
*/
void Property::setShowScalledPictures(bool theValue)
{
	if (theValue != this->showScalledPictures){
        showScalledPictures = theValue;
        emit this->propertyChanged(Property::ShowScalledPicture);
        }
}

/**
* Zwraca domyślny katalog
* @return QDir
*/
QDir Property::getPictureDir() const
{
        return pictureDir;
}

/**
* Ustawia domyślny katalog
*/
void Property::setPictureDir(const QDir& theValue)
{
        pictureDir = theValue;
}


QSize Property::getWindowSize() const
{
        return windowSize;
}


void Property::setWindowSize(const QSize& theValue)
{
        windowSize = theValue;
}


QPoint Property::getWindowPosition() const
{
        return windowPosition;
}


void Property::setWindowPosition(const QPoint& theValue)
{
        windowPosition = theValue;
}


Property::SortMethod Property::getSortMethod() const
{
        return sortMethod;
}


void Property::setSortMethod(const Property::SortMethod& theValue)
{
        sortMethod = theValue;
}
